﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Step4.Unit5.Models;
using System.Linq.Expressions;

namespace Step4.Unit5.Controllers
{
    public class StudentController : Controller
    {
        public List<Student> students= new List<Student>();

        public IActionResult Add()
        {
            ViewBag.ProvinceList = new SelectList(new List<ProvinceInfo>() 
            { 
                new(1,"北京"),
                new(2,"江西")
            },"Id","Name");
            return View();
        }

        public IActionResult Submit(Student student)
        {
            var exist = students.FirstOrDefault(p => p.Account.Equals(student.Account));
            if (exist!=null)
            {
                if (ModelState.IsValid)// 模型验证，视图模型验证通过
                {
                    return Redirect("/home/index");
                }
            }
            return Ok(student);
        }
    }

    public record ProvinceInfo(int Id,string? Name);

     
}
